package ee.ttu.karileet.serviceshop.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ee.ttu.karileet.serviceshop.dao.SubjectTypeDAO;
import ee.ttu.karileet.serviceshop.model.SubjectType;

@Service("subjectTypeDAO")
public class SubjectTypeDAOImpl implements SubjectTypeDAO {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void insertSubjectType(SubjectType object) {
		sessionFactory.getCurrentSession().save(object);
	}

	@Override
	public SubjectType getSubjectTypeById(long id) {
		return (SubjectType) sessionFactory.
			      getCurrentSession().
			      get(SubjectType.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<SubjectType> getSubjectTypes() {
	    Criteria criteria = sessionFactory.
	    	      getCurrentSession().
	    	      createCriteria(SubjectType.class);
	    return criteria.list();
	}

}
